{include file="common/pc/header" title="编辑部门" /}

<style>
    body {
        padding: 10px;
    }
</style>

<script>
    //config的设置是全局的
    layui.config({
        base: '/static/layui/mods' //假设这是你存放拓展模块的根目录
    }).extend({
        formSelects: '/formSelects/dist/formSelects-v4'
    });
</script>
<link rel="stylesheet" href="__STATIC__/layui/mods/formSelects/dist/formSelects-v4.css"/>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="showname"
                   placeholder="请输入姓名"
                   autocomplete="off" class="layui-input" value="{$editUser.showname}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="mobile"
                   placeholder="请输入手机号"
                   autocomplete="off" class="layui-input" value="{$editUser.mobile}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
            <select name="deptids" id="deptids" xm-select="deptids" xm-select-search></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">座机号</label>
        <div class="layui-input-block">
            <input type="text" name="telephone"
                   placeholder="请输入座机号"
                   autocomplete="off" class="layui-input" value="{$editUser.telephone}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email"
                   placeholder="请输入邮箱"
                   autocomplete="off" class="layui-input" value="{$editUser.email}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-block">
            <input type="text" name="position"
                   placeholder="请输入职位"
                   autocomplete="off" class="layui-input" value="{$editUser.position}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男"
                   {php}echo $editUser['sex'] == 1 ? "checked" : "";{/php}
            />
            <input type="radio" name="sex" value="0" title="女"
                   {php}echo $editUser['sex'] == 0 ? "checked" : "";{/php}
            />
            <input type="radio" name="sex" value="-1" title="保密"
                   {php}echo $editUser['sex'] == -1 ? "checked" : "";{/php}
            />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业管理员</label>
        <div class="layui-input-block">
            <input type="radio" name="isAdmin" value="1" title="是"
                   {php}echo $editUser['is_admin'] == 1 ? "checked" : "";{/php}
            />
            <input type="radio" name="isAdmin" value="0" title="否"
                   {php}echo $editUser['is_admin'] == 0 ? "checked" : "";{/php}
            />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">头像</label>
        <div class="layui-input-block">
            {d:up field="avatar" w="6rem" h="6rem" type="image" value="$editUser.avatar"}浏览{/d:up}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">入职时间</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="gmt_enter" id="gmtEnter"
                   value="{php}echo !empty($editUser['gmt_enter']) ? date('Y-m-d', $editUser['gmt_enter']) : '';{/php}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">政治面貌</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="political_status" value="{$editUser.political_status}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">工作性质</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="work_type" value="{$editUser.work_type}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="submit">更新</button>
        </div>
    </div>
</form>


{php}
$enterpriseJson = json_encode($enterprise);
{/php}
<script>
    var deptids = {$deptids};
    var deptTree = {$deptTree};
    var deptPath = {};
    var enterprise = {$enterpriseJson};
</script>

<script>
    /**
     * 初始化部门路径
     *
     * @param currentDeptId
     * @param currentDeptPath
     * @param currentDeptTreeChildItems
     */
    function initDeptPath(currentDeptId, currentDeptPath, currentDeptTreeChildItems) {
        deptPath[currentDeptId] = currentDeptPath;
        if (!currentDeptTreeChildItems) {
            return;
        }
        $.each(currentDeptTreeChildItems, function () {
            initDeptPath(this.id, currentDeptPath.concat(this.title), this.childs);
        });
    }

    layui.use(['form', 'formSelects','laydate'], function () {
        var form = layui.form;
        var formSelects = layui.formSelects;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#gmtEnter',
            type: 'date'
        });

        //初始化部门路径
        initDeptPath("1", [enterprise.title], deptTree);

        $.each(deptPath, function (index, value) {
            var selected = deptids.indexOf(index) !== -1 ? 'selected' : '';
            $("#deptids").append('<option value="' + index + '" ' + selected + '>' + value.join(" - ") + '</option>');
        });

        form.render();
        formSelects.render();

        //监听提交
        form.on('submit(submit)', function (data) {
            g.loading();
            $.post("", data.field, function (ret) {
                g.loading(false);
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                    document.location.href = "/core/enterprise.org.user/edit?userid={$editUser.id}";
                } else {
                    layer.alert(ret.msg);
                }
            }, "json");
            return false;
        });
    });

</script>

{include file="common/pc/footer"/}